package com.ln.design.mode.proxy.dynamic;

import com.ln.design.mode.proxy.SmsService;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Description SmsDynamicProxy
 * @Author zhangj
 * @Date 2022/11/29 23:00
 */
public class SmsDynamicProxy implements InvocationHandler {

    private final SmsService smsService;

    public SmsDynamicProxy(SmsService smsService) {
        this.smsService = smsService;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("发送消息之前");
        Object result = method.invoke(smsService, args);
        System.out.println("发送消息之后");
        return result;
    }
}
